package com.cn.jinl.controller;


import com.alibaba.fastjson.JSONObject;
import com.cn.jinl.api.IMeterPowerService;
import com.cn.jinl.domain.MeterPower;
import com.cn.jinl.utils.JsonResponse;
import com.cn.jinl.utils.QueryForm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/meterPower")
public class MeterPowerController {

    @Autowired
    private IMeterPowerService meterPowerService;

    @ResponseBody
    @RequestMapping("/getMeterPowerList/{frontToken}")
    public JsonResponse<Map<String,List<JSONObject>>> getMeterPowerList(QueryForm queryForm, @PathVariable(value = "frontToken", required = true) String frontToken) throws Exception {
        JsonResponse<Map<String,List<JSONObject>>> response = new JsonResponse<Map<String,List<JSONObject>>>();
        Map<String,List<JSONObject>> result = meterPowerService.getMeterPowerList(queryForm);
        response.setResult(result);
        response.setSuccess(true);
        return response;
    }

    @ResponseBody
    @RequestMapping("/getYearMeterPowers/{frontToken}")
    public JsonResponse<Map<String,List<MeterPower>>> getMeterPowerList(String year, @PathVariable(value = "frontToken", required = true) String frontToken) throws Exception {
        JsonResponse<Map<String,List<MeterPower>>> response = new JsonResponse<Map<String,List<MeterPower>>>();
        Map<String,List<MeterPower>> result = meterPowerService.getYearMeterPowers(year);
        response.setResult(result);
        response.setSuccess(true);
        return response;
    }

    @ResponseBody
    @RequestMapping("/getFirstPageYearMeterPowers")
    public JsonResponse<Map<String, Object[]>> getFirstPageYearMeterPowers() throws Exception {
        JsonResponse<Map<String, Object[]>> response = new JsonResponse<Map<String, Object[]>>();
        Map<String, Object[]> result = meterPowerService.getFirstPageYearMeterPowers();
        response.setResult(result);
        response.setSuccess(true);
        return response;
    }

    @ResponseBody
    @RequestMapping("/api/updateMeterTestPower")
    public JsonResponse<String> updateMeterTestPower() throws Exception {
        JsonResponse<String> response = new JsonResponse<String>();
        String result = meterPowerService.updateMeterTestPower();
        response.setResult(result);
        response.setSuccess(true);
        return response;
    }

}
